﻿/* file js for the tag-image game */

var Qv;
var Qk = new Array();
var myDiv;
var flag = false;
var time;

showSubmit = true;

function onready_user() {
    /*$("#answer_area").hide();*/
    $("#tag_area").val('');
}

/* instruction that the user want for the click of Gioca, Invia e Continua */
/* GIOCA */
function gameInit_click() {
    $("#myScore").hide();
    $("#answer_area").show();
    /* inizialize textBox*/
    $("#tag_area").val('inserisci il tag');
    /*clear textBox on_click*/
    $("#tag_area").click(function() {
        flag = true;
        $("#tag_area").val('');
    });
}

/* INVIA */
function sendAnswer_click() {
    $("#answer_area").hide();
    $("#myScore").show();
}

/* CONTINUA */
function nextChallenge_click() {
    $("#myScore").hide();
    $("#answer_area").show();
    $("#tag_area").val('inserisci il tag');
}

/* ----------------------------------------- */

/* function to print date */
function stampa() {

    Qv = iDocument;
    Qk = knowledge.split('|||');

    /* PROVVISORIO: da aggiungere oggetto SCORE */
    prevText = "Il tuo punteggio è: ";
    afterText = ". COMPLIMENTI!!!"

    $("#image_area").html("<img src=\"" + Qv + "\" alt=\"immagine da taggare\" title=\"immagine da taggare\" name=\"tagga\" width=\"350\" height=\"300\" border=\"0\" id=\"tagga\" />");

    $("#taboo_list").html("");

    for (i = 0; i < Qk.length; i++) {
        $("#taboo_list").append("<li id=\"taboo_" + i + "\">" + Qk[i] + "</li>");
    }

    return false;
}

/* function to control the answer before the send */
function checkAnswer(tmp_ans) {
    var result = -2; //default allow = pessima idea
    var stringa;

    if (jQuery.trim(tmp_ans) == '') {
        result = -1;
    }
    else {
        for (i = 0; i < Qk.length && result; i++) {
            if (Qk[i] == tmp_ans)
                result = i;
        }
    }
    if (!flag) result = -1;
    
    if (result > -2) {
        if (time) {
            clearTimeout(time);
            $("#tag_area").css("background-color", "White");
        }
        $("#tag_area").val('ERRORE! Inserisci un nuovo tag.');
        if (result > -1) {
            $("#taboo_" + result).animate({ "font-size": "30px" }, "medium");
            $("#taboo_" + result).animate({ "font-size": "18px" }, "medium"); 
         }
        $("#tag_area").css("background-color", "#eb008a");
        time = setTimeout("$(\"#tag_area\").css(\"background-color\", \"White\")", 1000);

    }
    flag = false;
    return result;
}

/* function to choose the value for the answer */
function prepareAnswer() {
    answer = "";
    answer = $("#tag_area").val();
}
